package com.yz.lzq.liwushuo.ui.modules.home.boutique;

import com.yz.lzq.liwushuo.http.HttpUtils;
import com.yz.lzq.liwushuo.http.OnGetNetDataListener;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.HomeBoutiqueBannerBean;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.HomeBoutiqueFenLeiBean;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/12/13.
 * 底部导航栏首页下的精品类的fragment的model层的接口
 */

public class HomeBoutiqueModel implements HomeBoutiqueContract.HomeBoutiqueModelInterface {
    /**
     * 获取banner的数据
     *
     * @param listener
     */
    @Override
    public void LoadHomeJinPinBannerBean(final OnGetNetDataListener<HomeBoutiqueBannerBean> listener) {
        /**
         * get请求 请求通过@queryMap注解动态的传递多个参数
         */
        Observable<HomeBoutiqueBannerBean> observable = HttpUtils.getInstance().getIApi().getHomeBoutiqueBannerBean();
        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<HomeBoutiqueBannerBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.onGetDataFalied(e);
                    }

                    @Override
                    public void onNext(HomeBoutiqueBannerBean homeBoutiqueBannerBean) {
                        listener.onGetDataSucess(homeBoutiqueBannerBean);
                    }
                });
    }

    /**
     * 获取分类的数据
     *
     * @param listener
     */
    @Override
    public void LoadHomeJinFenLeiBean(int gender, int generation, final OnGetNetDataListener<HomeBoutiqueFenLeiBean> listener) {
        /**
         * get请求 请求通过@queryMap注解动态的传递多个参数
         */
        //gender=1&generation=2
        Map<String, String> map = new HashMap<>();
        map.put("gender", gender + "");
        map.put("generation", generation + "");
        Observable<HomeBoutiqueFenLeiBean> observable = HttpUtils.getInstance().getIApi().getHomeJingPinFenLeiBean(map);
        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<HomeBoutiqueFenLeiBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(HomeBoutiqueFenLeiBean homeBoutiqueFenLeiBean) {
                        listener.onGetDataSucess(homeBoutiqueFenLeiBean);
                    }
                });
    }


}
